<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="编号" prop="sn">
        <el-input
          v-model="queryParams.sn"
          placeholder="请输入编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="reportList" @selection-change="handleSelectionChange">
      <el-table-column prop="formSn" label="换货单编号" align="center" />
      <el-table-column prop="stockSn" label="入库单编号" align="center" />
      <el-table-column prop="changeTime" label="换货日期" align="center">
        <template slot-scope="scope">
          {{ formatDate(scope.row.changeTime) }}
        </template>
      </el-table-column>
      <el-table-column prop="goodsSn" label="商品编号" align="center" />
      <el-table-column prop="goodsName" label="商品名称" align="center" />
      <el-table-column prop="categoryName" label="商品类别" align="center" />
      <el-table-column prop="specification" label="规格型号" align="center" />
      <el-table-column prop="unit" label="单位" align="center" />
      <el-table-column prop="changeType" label="调换类型" align="center" />
      <el-table-column prop="quantity" label="调换数量" align="center" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listChangeStatistics } from "@/api/system/ChangeStatistics";
import {formatDate} from "@/utils";


export default {
  name: "Report",
  data() {
    return {
      personList:[],
      damageTypes: [], // 报损类型列表
      // 部门选项
      deptOptions: [],
      // 仓库选项
      warehouseOptions: [],
      //用户选项
      userOptions: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 库存报损单表格数据
      reportList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        formSn: null,       // 换货单编号
        goodsSn: null,      // 商品编号
        goodsName: null,    // 商品名称
        changeType: null    // 调换类型
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    formatDate,
    /** 查询库存列表 */
    getList() {
      this.loading = true;
      listChangeStatistics(this.queryParams).then(response => {
        console.log(response);
        this.reportList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        sn: null,
        deptId: null,
        deptName: null,
        warehouseId: null,
        warehouseName: null,
        creatorId: null,
        creator: null,
        reportTime: null,
        damageTypeKey: null,
        damageTypeValue: null,
        reportDesc: null,
        createTime: null,
        status: null,
        rejectReason: null,
        auditTime: null,
        isAdd: false
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/report/export', {
        ...this.queryParams
      }, `report_${new Date().getTime()}.xlsx`)
    },
  }
};
</script>
